<?php

declare (strict_types=1);

namespace app\bbxw\controller;


use think\admin\Controller;

/**
 * 客户管理
 * @class Package
 * @package app\bbxw\controller
 */
class Customer extends Controller
{

    /**
     * 绑定数据表
     * @var string
     */
    private $table = 'customer';
    /**
     * 套餐管理
     * @auth true
     * @menu true
     * @login true
     */
    public function index()
    {

        $this->title = '客户管理';
        $query = $this->_query($this->table);
        // 列表排序并显示
        $query->like('name')->order('id desc')->page();

        $this->fetch();
    }

    /**
     * 图文列表数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _page_filter(array &$data)
    {
        foreach ($data as &$v){
            $prestore_amount  = $v['prestore_amount'];
            if(empty($v['prestore_amount'])){
                $prestore_amount = "0";
            }
            $use_amount  = $v['use_amount'];
            if(empty($v['prestore_amount'])){
                $use_amount = "0";
            }
            $v['balance'] = bcsub($prestore_amount,$use_amount,2);
        }
    }


    /**
     * 添加套餐
     * @auth true
     */
    public function add()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {

    }
    /**
     * 编辑套餐
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }

    public function backOrder()
    {
        $this->_form($this->table, 'back_order');
    }
    /**
     * 删除套餐
     * auth true
     */
    public function remove()
    {
        $this->_delete($this->table);
    }

}